package uid.jsf;

import java.util.ArrayList;
import java.util.List;

public class DataTable extends ComponenteAbstrato {

	private List<Column> colunas = new ArrayList<Column>();
	private String cabecalho;
	private String var;
	private String value;

	public String getCabecalho() {
		return cabecalho;
	}

	public void setCabecalho(String cabecalho) {
		this.cabecalho = cabecalho;
	}

	public String getVar() {
		return var;
	}

	public void setVar(String var) {
		this.var = var;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public DataTable(String id) {
		super(id);
	}

	public DataTable(String id, String cabecalho) {
		super(id);
		this.cabecalho = cabecalho;
	}

	public void adicionarColuna(Column c) {
		this.colunas.add(c);
	}

	@Override
	public String getJSF() {
		String r = "<h:dataTable value=\"#{BEAN.value" + this.value
				+ "}\" var=\"" + this.var + "\"  border=\"1\" >" + "\n";
		r += "<f:facet name=\"header\">" + "\n";
		r += new OutputText(this.cabecalho, this.cabecalho).getJSF() + "\n";
		r += "</f:facet>" + "\n";

		for (Column c : this.colunas) {
			r += c.getJSF() + "\n";
		}

		r += "</h:dataTable>" + "\n";
		return r;
	}
}
